<template>
  <div class="app-container">
    <div class="detailBox">
      <div class="touImg">
        <img v-if="form.avatar" :src="form.avatar" alt="">
        <img v-else src="../../static/avant.png" alt="" />
        <div class="name">{{form.nickName}}</div>
      </div>
      <div class="infoBox">
        <div class="list">
          <div class="lable">姓名：</div>
          <div class="content">{{form.name}}</div>
        </div>
        <div class="list">
          <div class="lable">手机号：</div>
          <div class="content">{{form.phoneNumber}}</div>
        </div>
        <div class="list">
          <div class="lable">实名认证：</div>
          <div class="content" v-if="form.name && form.idCard">{{form.name}}({{form.idCard}})</div>
          <div class="icon" v-else>未实名</div>
        </div>
        <div class="list">
          <div class="lable">注册时间：</div>
          <div class="content">{{form.createTime}}</div>
        </div>
        <div class="list">
          <div class="lable">钱包地址：</div>
          <div class="content">{{form.blockchainAddress}}</div>
        </div>
        <div class="list">
          <div class="lable">神椰CoCo：</div>
          <div class="content">{{form.coin}}</div>
        </div>
        <div class="list">
          <div class="lable">椰分：</div>
          <div class="content">{{form.tpoint}}</div>
        </div>
        <div class="list">
          <div class="lable">算力：</div>
          <div class="content">{{form.hashRate}}</div>
        </div>
        <div class="list">
          <div class="lable">产值系数：</div>
          <div class="content">{{form.outPutValue}}</div>
        </div>
      </div>
    </div>
    <div class="tableBox">
      <div class="head">
        <el-form :model="queryParams" ref="queryForm" :inline="true">
          <el-form-item label="积分类型：" prop="">
            <el-select v-model="queryParams.platformAssetType" placeholder="请选择" clearable :style="{width: inputWidth}"  @change="handleassetType">  
              <el-option v-for="dict in assetTypeLs" :key="dict.id" :label="dict.value" :value="dict.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="交易类型：" prop="">
            <el-select v-model="queryParams.changeType" placeholder="请选择" clearable :style="{width: inputWidth}">
              <el-option v-for="dict in changeTypeLsList" :key="dict.id" :label="dict.value" :value="dict.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="交易时间：" prop="">
            <el-date-picker v-model="date" start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false"
              type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 300px">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table v-loading="loading" :data="cardList" stripe border>
        <el-table-column label="序号" type="index" width="55" align="center" fixed />
        <el-table-column label="积分类型" align="center" prop="" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="assetTypeLs" :value="scope.row.platformAssetType" />
          </template>
        </el-table-column>
        <el-table-column label="交易类型" align="center" prop="changeTypeDict" :show-overflow-tooltip="true" />
        <el-table-column label="余额变动" align="center" prop="changeAmount" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-if="scope.row.type == 1">-{{scope.row.changeAmount}}</div>
            <div v-else>+{{scope.row.changeAmount}}</div>
          </template>
        </el-table-column>
        <el-table-column label="余额" align="center" prop="amount" :show-overflow-tooltip="true" />
        <el-table-column label="交易单号" align="center" prop="relevancyBusinessId" :show-overflow-tooltip="true" />
        <el-table-column label="交易时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>
<script>
  import {
    adminDict,
    getCustomer,
    customerCoinList,
  } from "@/api/members";
  import Dialog from "@/views/members/dialog";
  import NumDialog from "@/views/members/numDialog";
  export default {
    // dicts: ['customer_level_type', 'asset_card_class_type', 'asset_card_type', "customer_card_status",
    //   "asset_card_validity_type"
    // ],
    components: {
      Dialog,
      NumDialog
    },
    data() {
      return {
        date: [],
        labelWidth: '120px',
        inputWidth: '220px',
        loading: false,
        total: 0,
        form: {},
        cardList: [], //预付卡
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          customerId: '',
          platformAssetType: '', //积分类型 platform_asset_type
          changeType: '', //交易类型 platform_wallet_coco_log_change_type
          startDate: '', //计划发放开始时间
          endDate: '', //计划发放结束时间
        },
        assetTypeLs: [], //发放积分类型下拉
        changeTypeLs: [], //交易类型 CoCo下拉
        changeTypeLsNew: [],//交易类型  椰分下拉
        changeTypeLsList: [],
      };
    },

    created() {
      let query = this.$route.query;
      this.queryParams.customerId = query.id;
      this.getAssetType();
      this.getDictStatus();

      this.getInfo()
      this.getList()
    },
    methods: {
      //获取积分类型类型字典
      getAssetType() {
        var dictType = "platform_asset_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.assetTypeLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取交易类型字典
      getDictStatus() {
        var dictType = "platform_wallet_coco_log_change_type,platform_wallet_tf_log_change_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.changeTypeLs = res.result[0].dictList;
            this.changeTypeLsNew = res.result[1].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      handleassetType(e){
        console.log('e',e)
        this.changeTypeLsList = []
        if(e == 4){
          this.changeTypeLsList = this.changeTypeLs    
        }else if(e == 5){
          this.changeTypeLsList = this.changeTypeLsNew
        }
      },
      getInfo() {
        getCustomer(this.queryParams.customerId).then(response => {
          this.form = response.data;
        });
      },
      //获取coin详情列表
      getList() {
        this.loading = true;
        customerCoinList(this.queryParams).then(response => {
          this.total = response.result.total
          this.cardList = response.result.records
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.date = []
        this.queryParams.pageNum = 1
        this.queryParams.platformAssetType = ''
        this.queryParams.changeType = ''
        this.queryParams.startDate = ''
        this.queryParams.endDate = ''
        this.changeTypeLsList = []
        // this.resetForm("form");
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.startDate = this.date[0];
        this.queryParams.endDate = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
      },
    }
  };

</script>
<style lang="scss" scoped>
  // .app-container {
  //     background: #f5f5f5 !important;
  // }
  .detailBox {
    border-radius: 12px;
    padding: 20px;
    background: #fff;
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .touImg {
      display: flex;
      flex-direction: column;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }

      .name {
        margin-top: 10px;
        font-size: 18px;
        font-weight: 500;
        color: #333;
      }
    }
  }

  .infoBox {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
    margin-left: 24px;

    .list {
      min-width: 33.3%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      font-size: 14px;
      color: #333;
      margin-top: 10px;

      .content {
        display: flex;
        flex: 1;
      }
    }
  }

  .icon {
    background: #ccc;
    color: #fff;
    font-size: 12px;
    height: 20px;
    line-height: 20px;
    padding: 0 8px;
    border-radius: 2px;
  }

  .card_img {
    width: 100px;
    height: 60px;
  }

  .tableBox {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
  }

</style>
